package com.car.advertising.activity;
/**
 * @author luoan
 * @Description 引导页面
 * @version 1 初始化
 * @since 2016/01/27
 */

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.car.advertising.R;
import com.support.widget.JumpManager;
import com.support.widget.layout.BaseCommActivity;
import com.support.widget.view.viewPager.ViewPagerCompat;
import com.support.widget.view.viewPager.ZoomOutPageTransformer;

import java.util.ArrayList;
import java.util.List;


public class GuideViewActivity extends BaseCommActivity {

    private ViewPagerCompat guideVpc;
    private TextView homeJumpTv;

    private int[] mImgIds = new int[]{R.mipmap.guide_image1, R.mipmap.guide_image2, R.mipmap.guide_image3};
    private List<ImageView> mImageViews = new ArrayList<>();

    @Override
    protected void initView() {
        setContentView(R.layout.activity_guideview);
        guideVpc = (ViewPagerCompat) findViewById(R.id.guide_vpc);
        homeJumpTv = (TextView) findViewById(R.id.guide_home_jump_tv);
        homeJumpTv.setOnClickListener(this);

        initData();

        guideVpc.setPageTransformer(true, new ZoomOutPageTransformer());
        guideVpc.setAdapter(new PagerAdapter() {
            @Override
            public Object instantiateItem(ViewGroup container, int position) {

                container.addView(mImageViews.get(position));
                return mImageViews.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {

                container.removeView(mImageViews.get(position));
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public int getCount() {
                return mImgIds.length;
            }
        });

        guideVpc.setOnPageChangeListener(new ViewPagerCompat.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                homeJumpTv.setVisibility((position + 1) == mImageViews.size() ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//				Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();


    }

    @Override
    public String getCN() {
        return null;
    }

    @Override
    public void LogoutCallback(boolean islogin) {

    }

    @Override
    public void onCritClick(View v) {
        switch (v.getId()) {
            case R.id.guide_home_jump_tv:
                JumpManager.gotoActivity(GuideViewActivity.this, MainHomeActivity.class, false);
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    private void initData() {
        for (int imgId : mImgIds) {
            ImageView imageView = new ImageView(getApplicationContext());
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setImageResource(imgId);
            mImageViews.add(imageView);
        }
    }


}